Passed
Pull Request — master (#37)
by
unknown
03:48
created

zoom.ts ➔ createZoom   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
cc 1
1
import { DependencyNode, NodeSelection } from '../components/types';
2
import { ElementIds, MAXIMUM_ZOOM_SCALE, MINIMUM_ZOOM_SCALE } from '../utils/AppConsts';
3
import { zoom } from 'd3-zoom';
4
import { event } from 'd3-selection';
5
import { selectById } from '../utils/helpers/Selectors';
6
import { ZoomScaleStorage } from '../utils/helpers/UserEventHelpers';
7
8
export const changeZoom = (zoomSelector: ElementIds.OVERVIEW_ZOOM | ElementIds.DETAILS_ZOOM) => () => {
9
    const { transform } = event;
10
    const zoomLayer = selectById(zoomSelector);
11
    zoomLayer.attr('transform', transform);
12
    ZoomScaleStorage.setScale(transform.k);
13
};
14
15
export function createZoom(svgContainer: NodeSelection<SVGSVGElement>, selector: ElementIds.OVERVIEW_ZOOM | ElementIds.DETAILS_ZOOM) {
16
    const zoomLayer = svgContainer.append('g').attr('id', selector);
17
18
    svgContainer
19
        .call(
20
            zoom<SVGSVGElement, DependencyNode>()
21
                .scaleExtent([MINIMUM_ZOOM_SCALE, MAXIMUM_ZOOM_SCALE])
22
                .on(`zoom`, changeZoom(selector))
23
        )
24
        .on('dblclick.zoom', null);
25
26
    return zoomLayer;
27
}
28